<?php
    require('db_connection.php');
    $query = "SELECT * FROM tbllibrary";
    $result = mysql_query($query);
    $num = 1;
    $libctr= mysql_num_rows($result); // number of registered libraries
    $userID = $_COOKIE["user"];
    $sql = "SELECT * FROM tblclient WHERE userID LIKE '$userID'";
   
    $result1 = mysql_query($sql);
    while ($row = mysql_fetch_array($result1))
    {
      $libraryCardNo =$row['libraryCardNo'];
      $lastName = $row['lastName'];
      $firstName = $row['firstName'];
      $middleName = $row['middleName'];
      $address = $row['address'];
      $contactNo = $row['contactNo'];
      $schoolorg = $row['schoolorg'];
      $email = $row['email'];
      $userID = $row['userID'];
    }
?>

<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<html>

   <head>
      <title>La Union Online Library System -- My Account</title>
      <meta http-equiv='generator' content='PHP Designer 2005' />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>

    <body>
        <table  width='80%' align='center' cellspacing='0' cellpadding='0'>
            <tr ><td class='outerframe'>
                <table width='100%'  >
                <tr>
                    <td width='100%' colspan='2' class='outerframe2'>
                    <img src ='images/banner.jpg'>
                    </td></tr>
                <tr>
                    <td colspan='2' class='login'><?php require('loginout.php'); ?></td></tr>
                <tr>
                    <td width='20%' class='menu' valign='top'>
                    <?php require('menu.php'); ?>
                    </td>
                    <td class='content' width='80%' background ='images/background.jpg'>
                        <p class='titles' align='top'>My Account</p>
                        <table width='100%' class='loginform'>
                            <tr><td width='50%' colspan='4' class='logincontent'>If you have an existing library card in any public library in La Union, you can activate your account.<br><a href='activate.php' > Click here. </a></td>
                                <td colspan='4'><form method='post' action='login.php' name='login'>
                                <table  width='100%'  class='userlogin' cellspacing='3'>
                                <tr><td colspan='3' class='userloginheader'>Log-in <br></td></tr>
                                <tr><td>Library ID: </td>
                                <td><input name='libraryid'/></td>
                                <tr><td>Location:</td>
                              

                                    <td><select name='location'>
                                  <?php  while ($row = mysql_fetch_array($result))
                                    {
                                        $libraryNo = $row['libraryNo'];
                                        $location = $row['libraryName'];
                                        echo"<option value=$libraryNo>"." $location "." ";
                                    } ?>
     
                                </select></td></tr>
                                <tr><td>Password: </td><td><input type='password' name='password'></td></tr>
                                <tr><td class='logincontent' colspan='2' align='center'><a href='changepass.php'>[Change Password]</a></tr></td>
                                <tr><td class='buttons'colspan='2' align='center'>
                                <input type='submit' name='login' value='LOGIN' class='tool'/></td></tr></table>
                                <br>
                            </td> </tr>
                           <tr><td class='tableheader' width='100%' colspan='8'>Account Details</td></tr>
                                <?php
                                    echo"<tr ><td colspan='8' class='logincontent' align='center'><b>$firstName $middleName $lastName</b></td></tr>";
                                      echo "<tr><td align='right' colspan='4'>Library Card No.:<td colspan='4'> <b>$libraryCardNo</b></td></td></tr>";
                                      echo "<tr><td align='right'colspan='4'>Address:<td><b> $address </b></td></tr>";
                                      echo "<tr><td align='right' colspan='4'>School or Organization:<td colspan='4'><b> $schoolorg </b></td></tr>";
                                      echo "<tr><td align='right' colspan='4'>Contact No:<td> <b>$contactNo</b></td></tr>";

                                   ?>
                          
                            <tr><td class='tableheader' width='100%' colspan='8'>Existing Transactions</td></tr>
                            <tr class='title' align='center'><td></td><th>Call No.</b></th><th>Title</th><th>Author</th><th>Publisher</th><th>Status</th><th>Expiration Date</th></tr>


                    <?php

                    $ctr=1;

                    $query2= "SELECT * FROM tblcirculation WHERE userID LIKE '$userID'";
                    $result2 = mysql_query($query2);
                     while ($row = mysql_fetch_array($result2))
                        {
                            $materialID = $row['materialID'];
                            $status = $row['status'];
                            $dateExpire = $row['dateExpire'];
                            $query3= "SELECT * FROM tblcollection WHERE materialID='$materialID'";
                            $result3=mysql_query($query3);
                                while ($row = mysql_fetch_array($result3))
                                {
                                    //$result = mysql_query($query);
                                    $callNo = $row['callNo'];
                                    $title = $row['title'];
                                    $author = $row['author'];
                                    $publisher = $row['publisher'];
                                    $materialID = $row['materialID'];
                                    
                                    
                                    echo"<tr align='center' class='content'><td >$ctr.</td>";
                                    echo "<td >$callNo</td>
                                    <td >$title</td><td>$author</td>
                                    <td>$publisher</td>
                                    <td>$status</td>";
                                    echo"<td>$dateExpire</td>";
                                    echo "</form>";
                                    if($status == 'reserved')
                                    {
                                echo "<form method='post' action='delreserve.php?userID=$userID&materialID=$materialID' name='cancel'>";
                                      echo"<td><input type='submit' value='Cancel'></td></tr>";
                                      echo"</form>";
                                    }
                                    $ctr++;
                                }
                        }
                        
                    $ctr++;
            ?>

                                
                        </table></td></tr>
                        <tr><td>
                            
                            

           </td></tr>
                <tr>
                
               <td colspan='2' class='outerframe2'>
                 <?php require('contact.php'); ?>
                 </td></tr>
                </table>
        </td></tr></table>
    </body>
</html>
<?php

  mysql_close();
  
  //$libraryid = $_POST['libraryid'];
  //  authenticate($libraryid);

    


?>

